package com.rw.coco.event;

import com.rw.coco.api.event.PrivateMessageEvent;
import com.rw.coco.api.modle.Account;
import com.rw.coco.api.modle.Bot;
import com.rw.coco.model.MiraiAccount;
import com.rw.coco.model.MiraiBot;
import net.mamoe.mirai.contact.Friend;
import net.mamoe.mirai.contact.Stranger;
import net.mamoe.mirai.event.events.FriendMessageEvent;

public class MiraiPrivateMessageEvent implements PrivateMessageEvent {
    private final FriendMessageEvent friendMessageEvent;

    public MiraiPrivateMessageEvent(FriendMessageEvent friendMessageEvent) {
        this.friendMessageEvent = friendMessageEvent;
    }

    @Override
    public void delete() {
        friendMessageEvent.getFriend().delete();
    }

    @Override
    public Bot getBot() {
        net.mamoe.mirai.Bot bot = friendMessageEvent.getBot();
        return new MiraiBot(String.valueOf(bot.getId()), bot.getNick());
    }

    @Override
    public String getMessage() {
        return friendMessageEvent.getMessage().contentToString();
    }

    @Override
    public Account getSender() {
        Friend sender = friendMessageEvent.getSender();
        return new MiraiAccount(String.valueOf(sender.getId()), sender.getNick(), sender.getNick());
    }

    @Override
    public void sendBack(String message) {
        friendMessageEvent.getSubject().sendMessage(message);
    }

    @Override
    public void sendBackSender(String message) {
        friendMessageEvent.getSubject().sendMessage(message);
    }

    @Override
    public void sendPrivate(String message, String accountId) {
        Stranger stranger = friendMessageEvent.getBot().getStranger(Long.parseLong(accountId));
        if (stranger != null) {
            stranger.sendMessage(message);
        }
    }
}
